<?php
namespace App\Admin\Models;
use Common\BaseModel;
class CollegeCarousel extends BaseModel
{
    protected $res;
    protected $key="admin_";
    public function initialize()
    {
        parent::initialize();
        $this->setSource('f_college_carousel');
    }



    /**
     * 获取具体的内容
     * @param int $cid 栏目id
     * @param int $cateid 分类id
     * @param int $is_recommend 是否首页推荐 0不需要首页推荐 1首页推荐
     * @param int $type 根据类型获取内容
     * @return mixed
     */
    public function find_list($params){
        $conditions='';
        if(isset($params['cid']) && !empty($params['cid'])){
            if($conditions){
                $conditions .= " AND cid={$params['cid']}";
            }else{
                $conditions .= "cid={$params['cid']}";
            }
        }

        if(isset($params['cateid']) && !empty($params['cateid'])){
            if($conditions){
                $conditions .= " AND cateid={$params['cateid']}";
            }else{
                $conditions .= "cateid={$params['cateid']}";
            }
        }

        if(isset($params['is_recommend']) && !empty($params['is_recommend'])){
            if($conditions){
                $conditions .= " AND is_recommend={$params['is_recommend']}";
            }else{
                $conditions .= "is_recommend={$params['is_recommend']}";
            }
        }

        if(isset($params['type']) && !empty($params['type'])){
            if($conditions){
                $conditions .= " AND type={$params['type']}";
            }else{
                $conditions .= "type={$params['type']}";
            }
        }
        $order="sort ASC,id ASC";
        $carousel_list = $this::find(
            array(
                $conditions,
                "order" => $order,
            )
        );
        return $carousel_list;
    }


    public function find_cout($cid){
        $conditions="cid={$cid}";
        $count = $this::count(
            array(
                $conditions,
                "columns"=>'id'
            )
        );
        return $count;
    }

    public function find_cate_cout($cateid){
        $conditions="cateid={$cateid}";
        $count = $this::count(
            array(
                $conditions,
                "columns"=>'id'
            )
        );
        return $count;
    }



    /**
     * 根据id获取分类
     */
    public function find_by_id($id){
        $info = $this->findFirstById($id)->toarray();
        if($info){
            return $info;
        }else{
            return [];
        }
    }


    public function save_params($params){
        return $this::save($params);
    }

}
